package cn.zhuo.knowledge.util.hutool.crypto.digest;

import cn.hutool.core.util.IdUtil;
import cn.hutool.crypto.digest.DigestUtil;
import cn.hutool.crypto.digest.MD5;

import java.nio.charset.StandardCharsets;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * <p>
 *
 * @author z2huo
 */
class DigestTest {

    public static void main(String[] args) {
        String snowflakeNextId = IdUtil.getSnowflakeNextIdStr();

        String md5Str = DigestUtil.md5Hex(snowflakeNextId);
        System.out.println(md5Str);
        System.out.println(md5Str.length());
        System.out.println();

        String md516Str = DigestUtil.md5Hex16(snowflakeNextId);
        System.out.println(md516Str);
        System.out.println(md516Str.length());
        System.out.println();

        String salt = LocalDateTime.now().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME);
        MD5 md5 = new MD5(salt.getBytes(StandardCharsets.UTF_8));
        String saltMd5 = md5.digestHex16(snowflakeNextId);
        System.out.println(saltMd5);
        System.out.println(saltMd5.length());
        System.out.println();


        String sha1Str = DigestUtil.sha1Hex(snowflakeNextId);
        System.out.println(sha1Str);
        System.out.println(sha1Str.length());
        System.out.println();

        String sha256Str = DigestUtil.sha256Hex(snowflakeNextId);
        System.out.println(sha256Str);
        System.out.println(sha256Str.length());
        System.out.println();

        String sha512Str = DigestUtil.sha512Hex(snowflakeNextId);
        System.out.println(sha512Str);
        System.out.println(sha512Str.length());
        System.out.println();
    }
}
